package com.syf.kit.soa.config;

import com.syf.kit.soa.SOARegionDocument;
import com.syf.kit.soa.core.SyfRemoteServiceInvoker;
import com.syf.kit.soa.core.send.SyfRpcSender;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(SySOAClientConfiguration.class)
public class SySOAClientAutoConfig {

    @ConditionalOnBean(SOARegionDocument.class)
    @Bean(name = "service-remote-invoker")
    SyfRemoteServiceInvoker createSyfRemoteServiceInvoker(SySOAClientConfiguration configuration, SOARegionDocument regionDocument) {
        SyfRpcSender rpcSender = new SyfRpcSender(regionDocument, configuration);
        return new SyfRemoteServiceInvoker(rpcSender);
    }
}
